/*
 * OPIAM Suite
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package opiam.admin.faare.config.javabeans;

import opiam.admin.faare.service.services.references.ReferenceList;


/**
 * This class conveys a reference list based on a single object.
 *
 */
public class JBBaseReferenceListDescriptor implements java.io.Serializable
{
    /** Reference list name. */
    private String name;

    /** Reference list scope. */
    private String scope = ReferenceList.SCOPE_SESSION;

    /** Dname of the entry containing the reference list values. */
    private String dn;

    /** Name of the attribute containing the reference list values. */
    private String attr;

    /** "Values to parse" flag. */
    private String parse;

    /**
     * Returns the name of the referebce list.
     * @return name
     */
    public String getName()
    {
        return name;
    }

    /**
     * Sets the name of the reference list.
     * @param aname The name to set
     */
    public void setName(String aname)
    {
        this.name = aname;
    }

    /**
     * Checks whether the reference list is application scoped.
     *
     * @return true if it is, false if it is not.
     */
    public boolean isScopeApplication()
    {
        return (scope.compareToIgnoreCase(ReferenceList.SCOPE_APPLICATION) == 0);
    }

    /**
     * Checks whether the reference list is session scoped.
     *
     * @return true if it is, false if it is not.
     */
    public boolean isScopeSession()
    {
        return (scope.compareToIgnoreCase(ReferenceList.SCOPE_SESSION) == 0);
    }

    /**
     * Checks whether the reference list is request scoped.
     *
     * @return true if it is, false if it is not.
     */
    public boolean isScopeRequest()
    {
        return (scope.compareToIgnoreCase(ReferenceList.SCOPE_REQUEST) == 0);
    }

    /**
     * Returns the name of the attribute containing the reference list values.
     * @return name of the attribute
     */
    public String getAttr()
    {
        return attr;
    }

    /**
     * Returns the dname of the entry containing the reference list values.
     * @return dname
     */
    public String getDn()
    {
        return dn;
    }

    /**
     * Returns the "Values to parse" flag.
     * @return flag
     */
    public String getParse()
    {
        return parse;
    }

    /**
     * Sets the name of the attribute containing the reference list values.
     * @param aattr The attribute name to set
     */
    public void setAttr(String aattr)
    {
        this.attr = aattr;
    }

    /**
     * Sets the dname of the entry containing the reference list values.
     * @param adn The dname to set
     */
    public void setDn(String adn)
    {
        this.dn = adn;
    }

    /**
     * Sets the "Values to parse" flag.
     * @param aparse The flag to set
     */
    public void setParse(String aparse)
    {
        this.parse = aparse;
    }

    /**
     * Checks whether list values have to be parsed or not.
     *
     * @return true if they have to, false if they don't have to.
     */
    public boolean isToParse()
    {
        return (parse.compareToIgnoreCase("true") == 0);
    }

    /**
     * Displays the reference list definition.
     *
     * @return String formatted reference list definition.
     */
    @Override
	public String toString()
    {
        StringBuffer buf = new StringBuffer();
        java.util.Iterator it = null;

        buf.append("name = ");
        buf.append(name);
        buf.append(System.getProperty("line.separator"));
        buf.append("scope = ");
        buf.append(scope);
        buf.append(System.getProperty("line.separator"));
        buf.append("dn = ");
        buf.append(dn);
        buf.append(System.getProperty("line.separator"));
        buf.append("attr = ");
        buf.append(attr);
        buf.append(System.getProperty("line.separator"));
        buf.append("parse = ");
        buf.append(parse);
        buf.append(System.getProperty("line.separator"));

        return buf.toString();
    }

    // end of toString method

    /**
     * Returns the scope.
     * @return scope
     */
    public String getScope()
    {
        return scope;
    }

    /**
     * Sets the scope.
     * @param ascope The scope to set
     */
    public void setScope(String ascope)
    {
        this.scope = ascope;
    }
}
